package com.skirmisher.inspection.common.controller;

import com.skirmisher.inspection.common.entity.InsFile;
import com.skirmisher.inspection.common.entity.InsUser;
import com.skirmisher.inspection.common.service.InsFileService;
import com.skirmisher.inspection.common.utils.PageUtils;
import com.skirmisher.inspection.inspection.testController.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName InsFileController
 * @Description TODO
 * @Author hanwangxin
 * @Date 2020/12/14 下午7:46
 * @Version 1.0
 */
@Api(tags = "巡查附件与人员获取相关接口")
@RestController
@RequestMapping("/app_placeLog")
public class InsFileController {

    @Autowired
    private InsFileService insFileService;

    @ApiOperation(value = "保存oss文件列表")
    @PostMapping(value = "/saveFile")
    public ResponseModel saveFile(@RequestBody @Validated InsFile insFile){

        ResponseModel responseModel = new ResponseModel();

        insFileService.saveFile(insFile);

        return  responseModel;
    }

    @ApiOperation(value = "获取oss文件列表")
    @GetMapping(value = "/getFileList")
    @ApiImplicitParam(name = "bindId",value = "业务数据id",required = true)
    public ResponseModel getFileList(String bindId){

        ResponseModel responseModel = new ResponseModel();

        List<InsFile> fileList = insFileService.getFileList(bindId);

        responseModel.setData(fileList);
        return  responseModel;
    }

    @ApiOperation(value = "获取人员列表")
    @GetMapping(value = "/getUser")
    public ResponseModel getUser(InsUser user){

        ResponseModel responseModel = new ResponseModel();
        if (user.getPage() != 0 && user.getRows() != 0){
            Integer startRow = PageUtils.getStartRow(user.getPage(), user.getRows());
            user.setStartRows(startRow);
        }
        insFileService.getUser(user);
        responseModel.setDataDataGrid(user.getDateList(),user.getCount());
        return  responseModel;
    }
}
